package com.chen.mobiletwo.controller;

import com.chen.mobiletwo.service.PanService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/Pan/")
public class PanController {
    private static final Logger logger= LoggerFactory.getLogger(PanController.class);//日志getLogger需要传入的类名
    @Resource
    private RedisTemplate<String ,String> redisTemplate;//Redis工具类
    @Resource
    PanService panService;

    /**
     * 无条件查所有数据 不分页
     * @return json
     */
    @GetMapping("getPanList")
    private String getPanList()
    {
        return panService.getPanList();
    }

    /**
     * 根据id 删除数据
     * @param pId id
     * @return json
     */
    @DeleteMapping("delPan")
    private String delPan(@RequestParam("pId") int pId){
        return panService.delPan(pId);
    }

    /**
     * 根据id 修改所有数据
     * @param pId id
     * @param pName 名字
     * @param pweChat 微信号
     * @param pqqNum qq
     * @return json
     */
    @PostMapping("upPan")
    private String upPan(@RequestParam("pId") int pId,
                         @RequestParam("pName") String pName,
                         @RequestParam("pweChat") String pweChat,
                         @RequestParam("pqqNum") String pqqNum){
        return panService.upPan(pId,pName,pweChat,pqqNum);
    }

    /**
     * 添加数据
     * @param pName 名字
     * @param pweChat 微信
     * @param pqqNum qq
     * @return json
     */
    @PostMapping("addPan")
    private String addPan(@RequestParam("pName") String pName,
                         @RequestParam("pweChat") String pweChat,
                         @RequestParam("pqqNum") String pqqNum){
        return panService.addPan(pName,pweChat,pqqNum);
    }
}
